package com.thread.practice;

/**
 * @description:
 * @author: 刘建楼
 * @create: 2021-04-20
 **/
public class Print {
    // 标识账户中是否已有存款的旗标
    private boolean flag = false;
    private Integer count = 1;

    public synchronized void printNumber() {
        try {
            if (flag) {
                wait();
            }
            System.out.print(2 * count - 1);
            System.out.print(2 * count);
            flag = true;
            notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void printLetters() {
        try {
            if (!flag) {
                wait();
            }
            System.out.print((char) ('A' + (count - 1)));
            count++;
            flag = false;
            notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
